The present invention relates in general to a time-of-day clock implemented using a microcontroller, and more specifically to correcting for time keeping inaccuracies resulting from frequency errors of a crystal oscillator.
Microprocessor and microcontroller systems operate using internal timing circuits for coordinating processing operations and establishing machine timing cycles for execution of instructions. A crystal oscillator is frequently employed to provide timing signals for the microprocessor due to the relatively high accuracy and stability of piezoelectric crystals.
One of the functions that is often performed using a microprocessor or microcontroller is that of a time-of-day clock. Such a clock is implemented using time values stored in memory which are updated periodically by the microprocessor which counts timing signals received from the crystal oscillator. Typically, the time-of-day function is incidental to some other primary control function being implemented using the microcontroller, such as control of an automotive audio system. Proper operation of that primary control function is not highly dependent upon the accuracy of the internal clock which is driven by the piezoelectric crystal oscillator. However, in implementing a time-of-day clock using the microcontroller, a crystal oscillator error amounting to even a few parts per million causes a significant timing error to eventually be accumulated in the time-of-day clock.
Typical manufacture of piezoelectric crystals results in a variability of the crystal's resonant frequency of about 20 parts per million (ppm). In order microcontroller time-of-day clocks, crystals can be presorted into various value ranges by the crystal manufacturer and subsequently matched with particular values of load capacitors for constructing each individual crystal oscillator. Such sorting and matching of components increases the cost of the clock.
Another method for obtaining accurate oscillator signals is to provide a variable load capacitor to allow adjustment (i.e., trimming) of the oscillator frequency. However, the variable capacitor and the need for manual calibration add expense to the oscillator.
It is preferable to manufacture an oscillator using unmatched, standard tolerance components without special trimming capacitors. Therefore, there have been attempts to allow the oscillator to run at an incorrect frequency, measure the frequency error, and compensate for the error within the microcontroller as it keeps track of time-of-day. For example, Luitje (U.S. Pat. No. 4,708,491), discloses an untrimmed crystal circuit connected to the oscillator of a microcomputer. After frequency prescaling, the timing signal is measured to determine an error value. A correction term is stored in the microcomputer via entry from a keyboard. During clock operation, the value in a free-running counter is compared to a programmable register. Interrupts are generated when the number in the programmable register equals the number in the free-running counter. The interrupts provide a time base for keeping track of time-of-day. The correction term is used in loading the programmable register once each second so that the time intervals of the interrupts themselves are error corrected.
The ability to change the period between interrupt signals is essential to the technique disclosed in Luitje. However, not all microcontrollers provide user access to the interrupt interval. For example, the COP888 family of microcontrollers manufactured by National Semiconductor Corporation use an idle timer for providing a time base. The idle timer is a free-running 16-bit timer which is clocked from the crystal oscillator via a divide-by-10 circuit. Whenever the 12th bit toggles its value, an interrupt is generated by the idle timer which can be used to update various time-of-day counters. The period between these interrupts is not programmable and depends only upon oscillator frequency. Therefore, the technique described in Luitje cannot be used. Furthermore, the calculations required to apply error correction to the programmable register value and the need to correct for inaccuracies each and every second increases the processor overhead associated with use of the Luitje technique to an undesirable level.